package com.lqm.entity.home;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * @program: CrowdFunding
 * @description
 * @author: lqm
 * @create: 2018-12-06 17:28
 */

@Entity
@Table(name = "user_address", schema = "crowdfunding", catalog = "")
public class UserAddress  implements Serializable {
    private Integer addressId;

    private String addressDetail;
    private String addressProvide;
    private String addressCity;
    private String addressArea;

    private String addressPhone;
    private Integer isDefault=0;
    private String consigneeName;
    private Integer status=1;
    @JsonBackReference
    private HomeUser homeUser;

    @Id
    @Column(name = "address_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getAddressId() {
        return addressId;
    }

    public void setAddressId(Integer addressId) {
        this.addressId = addressId;
    }

    @Basic
    @Column(name = "consignee_name", nullable = true, length = 255)
    public String getConsigneeName() {
        return consigneeName;
    }

    public void setConsigneeName(String consigneeName) {
        this.consigneeName = consigneeName;
    }


    @Basic
    @Column(name = "address_detail", nullable = true, length = 255)
    public String getAddressDetail() {
        return addressDetail;
    }

    public void setAddressDetail(String addressDetail) {
        this.addressDetail = addressDetail;
    }
    @Basic
    @Column(name = "address_provide", nullable = true, length = 30)
    public String getAddressProvid() {
        return addressProvide;
    }

    public void setAddressProvid(String addressProvide) {
        this.addressProvide = addressProvide;
    }

    @Basic
    @Column(name = "address_city", nullable = true, length = 30)
    public String getAddressCity() {
        return addressCity;
    }

    public void setAddressCity(String addressCity) {
        this.addressCity = addressCity;
    }
    @Basic
    @Column(name = "address_area", nullable = true, length = 30)
    public String getAddressArea() {
        return addressArea;
    }

    public void setAddressArea(String addressArea) {
        this.addressArea = addressArea;
    }

    @Basic
    @Column(name = "address_phone", nullable = true, length = 255)
    public String getAddressPhone() {
        return addressPhone;
    }

    public void setAddressPhone(String addressPhone) {
        this.addressPhone = addressPhone;
    }

    @Basic
    @Column(name = "is_default", nullable = true, length = 255)
    public Integer getIsDefault() {
        return isDefault;
    }

    public void setIsDefault(Integer isDefault) {
        this.isDefault = isDefault;
    }

    @Basic
    @Column(name = "status", nullable = false)
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        UserAddress that = (UserAddress) o;
        return Objects.equals(addressId, that.addressId) &&
                Objects.equals(consigneeName, that.consigneeName) &&
                Objects.equals(addressDetail, that.addressDetail) &&
                Objects.equals(addressPhone, that.addressPhone) &&
                Objects.equals(isDefault, that.isDefault) &&
                Objects.equals(status, that.status) &&
                Objects.equals(homeUser, that.homeUser);
    }

    @Override
    public int hashCode() {
        return Objects.hash(addressId, consigneeName, addressDetail, addressPhone, isDefault, status, homeUser);
    }

    @ManyToOne
    @JoinColumn(name = "address_user_id")
    public HomeUser getHomeUser() {
        return homeUser;
    }

    public void setHomeUser(HomeUser homeUser) {
        this.homeUser = homeUser;
    }

    @Override
    public String toString() {

        return "UserAddress{" +
                "addressId=" + addressId +
                ", addressDetail='" + addressDetail + '\'' +
                ", addressProvide='" + addressProvide + '\'' +
                ", addressCity='" + addressCity + '\'' +
                ", addressArea='" + addressArea + '\'' +
                ", addressPhone='" + addressPhone + '\'' +
                ", isDefault=" + isDefault +
                ", consigneeName='" + consigneeName + '\'' +
                ", status=" + status +
//                ", homeUser=" + homeUser +
                '}';
    }
}
